<?php
$ft = "";
function createThumb($sourceimg, $preferedSize){
//$file_ext = 
$filetype = substr(strchr($sourceimg,"."),1);
if($filetype=="jpg")
{
	$filetype ="jpeg";
	$mainImage = imagecreatefromjpeg($sourceimg);
}else if($filetype=="gif")
{
	$mainImage = imagecreatefromgif($sourceimg);
}else if($filetype=="png")
{
	$mainImage = imagecreatefrompng($sourceimg);
}


$mainWidth = imagesx($mainImage);
$mainHeight = imagesy ($mainImage) ;
if($mainWidth<$preferedSize && $mainHeight <$preferedSize)
{
	$thumbWidth = $mainWidth;
	$thumbHeight = $mainHeight;
}else { 
	
	$thumbHeight = intval(($mainHeight *$preferedSize) /$mainWidth);
	$thumbWidth = $preferedSize;
}
if($filetype=="jpeg")
{
	$myThumbnail =imagecreatetruecolor($thumbWidth, $thumbHeight);
}else{
$myThumbnail = imagecreate($thumbWidth, $thumbHeight);
}
header("Content-type: image/".$filetype."");
$GLOBALS["ft"] = $filetype;
imagecopyresampled($myThumbnail, $mainImage, 0, 0,0,0, $thumbWidth,$thumbHeight, $mainWidth, $mainHeight);
return  $myThumbnail;

}

$folder = $_GET['f'];
$image = $_GET['im'];
$sz=$_GET['sz'];
switch($sz)
{
	case "ss":$size=25;break;
	case "sm":$size=50;break;
	case "md":$size=100;break;
	case "me":$size=150;break;
	case "snews";$size=250;break;
	case "sbig":$size=250;break;
	case "vbig":$size=450;break;
	default:$size=570;
}
//createThumb($image, $size);
$th = createThumb($image, $size);
if($ft =="jpeg")
imagejpeg($th);
else if($ft=="gif")
imagegif($th);
else if($ft=="png")
imagepng($th);
imagedestroy ($th);

?>

